# -*- coding: utf-8 -*-
import cherrypy
from sqlalchemy import Column, Integer, String
import db


class User(db.Base):

    __tablename__ = 'users'
    username = Column(String, primary_key=True)
    password = Column(String)
    email = Column(String)

    def __init__(self, username, password, email = None):
        self.username = username
        self.password = password
        self.email = email

    def __repr__(self):
        return "<User('{}','{}', '{}')>".format(self.username, self.password, self.email)

def email():
    if db.SESSION_KEY in cherrypy.session.keys() and cherrypy.session[db.SESSION_KEY]:
        return session.query(User).get(5).email

def vkontakte_id():
    if db.SESSION_KEY in cherrypy.session.keys() and cherrypy.session[db.SESSION_KEY]:
        try:
            int(cherrypy.session[db.SESSION_KEY])
            return cherrypy.session[db.SESSION_KEY]
        except:
            return ''


db.Base.metadata.create_all(db.engine) #create table
